home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_s / startrek.zip / CHAPTER.007 < prev    next >
Text File  |  1989-05-15  |  57KB  |  1,123 lines

  1.         Chapter 7 PAGE 1 STARTREK THE COMPUTER PROGRAM
  2.  
  3.  
  4.                                     CHAPTER 7
  5.  
  6.         7.1  The ENDGAME Routine
  7.  
  8.              Moving  the Enterprise around in space uses fuel or  energy.  
  9.         There is thus a probability that the Enterprise will exhaust  its 
  10.         supply  and that condition must be taken care of before the  move 
  11.         subroutine is added to the program.
  12.  
  13.              There  are  five different ways in which the game  can  end. 
  14.         They are as follows.
  15.  
  16.         1    The player resigns and ends the game voluntarily.
  17.         2    The Enterprise is destroyed by enemy action.  
  18.         3    The  Enterprise  runs out of energy before  the  mission  is 
  19.              completed.
  20.         4    The allotted time for the game is over before the mission is 
  21.              completed.
  22.         5    All  the enemy ships are destroyed by the player.   This  is 
  23.              the only case in which the player actually 'wins' the game.
  24.  
  25.              The  main  loop of the program is performed as long  as  the 
  26.         'game over flag' (F9) remains equal to zero. It is however set to 
  27.         a  non-zero condition when one of the five conditions for  ending 
  28.         the game is encountered.  When the flag is set, the program  flow 
  29.         branches  away  from  the  main loop to the  'End  of  the  game' 
  30.         sequence.
  31.  
  32.              The  flowchart for the End of the game sequence is shown  in 
  33.         figure 7.1.  Various routines not yet discussed set up some value 
  34.         in F9 when one of the conditions to end the game is  encountered.  
  35.         The  End of the game sequence tests to see which of them was  set 
  36.         up and displays messages accordingly.
  37.  
  38.              The  player's  score at the instant the game ended  is  then 
  39.         displayed,  and  some  dialog ensures as the  computer  asks  the 
  40.         player to decide if another game is desired.  If another game  is 
  41.         desired,  the computer first prompts the player to standby,  then 
  42.         re-initializes various variables and flags.  Lastly, the  mission 
  43.         message  is displayed that tells the player how many enemy  ships 
  44.         have to be destroyed in how much time, and the program flow picks 
  45.         up again at the main command loop.
  46.  
  47.              If  the player does not want another game, the program  ends 
  48.         and control is returned to the BASIC command level.
  49.  
  50.              A  BASIC  language  implementation of the End  of  the  game 
  51.         sequence is shown in figure 7.2.  It begins at line 9000 with the 
  52.         usual REMark statement.  Line 9010 first does a 'PRINT' statement 
  53.         to move the cursor down one line.  At this time, the 'End of  the 
  54.         game flag' contains one of five different values between 1 and 5.  
  55.         The statement
  56.                        ON F9 GOTO 9020,9040,9080,9130,9160
  57.         routes the program flow to the correct line corresponding to  the 
  58.         value  in  F9.   You will remember that  the  'ON'  statement  is 
  59.  
  60.  
  61.         Copyright (c) Joe Kasser 1989
  62.  
  63.  
  64.  
  65.  
  66.  
  67.         Chapter 7 PAGE 2 STARTREK THE COMPUTER PROGRAM
  68.  
  69.  
  70.         equivalent  to a sequence of 'IF/THEN' statements.  In this  case 
  71.         the equivalent  statements would be
  72.         9011 IF F9=1 THEN 9020
  73.         9012 IF F9=2 THEN 9040
  74.         9013 IF F9=3 THEN 9080
  75.         9014 IF F9=4 THEN 9130
  76.         9015 IF F9=5 THEN 9160
  77.  
  78.              When  F9=1,  the player has voluntarily  resigned  from  the 
  79.         game.   The Resignation ending begins at line 9020.   Nothing  is 
  80.         displayed  here  because it was all taken care of in  the  dialog 
  81.         that  was part of the still to be described Resignation  command.  
  82.         The line thus only contains a 'REM' statement and the next  line, 
  83.         line 9030 jumps the program flow forward to line 9180.
  84.  
  85.              When  F9=2,  the  Enterprise  has  been  destroyed  by   the 
  86.         Klingons.   This ending begins at line 9040 with the usual  'REM' 
  87.         statement.  Line 9050 then displays a message to the effect  that 
  88.         the  Enterprise  has  been  destroyed.   Line  9060  displays   a 
  89.         sarcastic message about the quality of the player's ability as  a 
  90.         Captain  and  line 9070 jumps the program flow  forward  to  line 
  91.         9180.
  92.  
  93.              When F9=3 the player has run out of energy in the middle  of 
  94.         the  mission.   Line  9080 starts that sequence  with  the  usual 
  95.         REMark.  Line 9090 displays a message telling the player that the 
  96.         Enterprise  has indeed run out of energy.  The 'PRINT'  statement 
  97.         at  the  end of the line advances the cursor down  one  line,  or 
  98.         inserts  a  blank line between what was just displayed  and  what 
  99.         comes next.
  100.  
  101.              Line  9100 and 9110 display a sarcastic comment telling  the 
  102.         player  that  the Captain, the ship and the crew have  just  been 
  103.         condemned to a horrible, lingering  and un-necessary death as the 
  104.         life support systems on-board the Enterprise fail one by one  due 
  105.         to  the  lack  of energy.  There is no hope  of  rescue,  because 
  106.         without  energy,  there  is  no way to  get  in  touch  with  any 
  107.         potential rescuers.  Line 9120 then advances the program  counter 
  108.         to line 9180.
  109.  
  110.              When  F9=4  the player has run out of time.   That  sequence 
  111.         picks up at line 9130 with the usual REMark statement.  Line 9104 
  112.         tells  the player in no uncertain terms why the game  has  ended, 
  113.         and line 9150  jumps the program counter forward to line 9180.
  114.  
  115.              When  F9=5  the player has destroyed all the  enemy  vessels 
  116.         within  the allotted amount of time.  This sequence picks  up  at 
  117.         line  9160  with  the  customary  REMark  statement.   Line  9170 
  118.         displays a message congratulating the player on winning the game, 
  119.         and the program counter falls through to line 9180.
  120.  
  121.              Line 9180 uses a 'PRINT' statement to generate a blank  line 
  122.         at the cursor and then calls the subroutine starting at line  170 
  123.         to display the player's score at the instant the game ended.  The 
  124.         line  continues with the dialog to determine if the player  wants 
  125.  
  126.  
  127.         Copyright (c) Joe Kasser 1989
  128.  
  129.  
  130.  
  131.  
  132.  
  133.         Chapter 7 PAGE 3 STARTREK THE COMPUTER PROGRAM
  134.  
  135.  
  136.         another game.
  137.  
  138.              The  player  is  prompted for an  input  using  the  'INPUT' 
  139.         statement.   The  format of the expected reply is also  given  as 
  140.         part of the prompt, ie. the (Yes/No) part.  Notice also the space 
  141.         before  the  last quotation mark.  The reply is assigned  to  the 
  142.         dialog  string variable A$ (Answer$).  The last statement on  the 
  143.         line  tests  the  answer  in A$ to see if  it  is  at  least  one 
  144.         character long.  The 'LEN(A$)' function is used to determine  how 
  145.         many  characters have been put into A$.  If the answer  is  zero, 
  146.         then  none have been put into the string, ie. the  player  pushed 
  147.         the  'carriage return' or 'enter' key without first entering  the 
  148.         correct  response.  If that condition is in effect,  the  program 
  149.         counter is reset to line 9180 which displays the score once more, 
  150.         and and repeats the question.
  151.  
  152.              Line  9190 tests the first characters in A$ to see if it  is 
  153.         an  "N".   If it is, the program flow jumps to line  9230.   Line 
  154.         9200 tests the first character of the string to make sure that it 
  155.         is  not equal to a "Y".  If the character is not equal to a  "Y", 
  156.         the  the player has not answered the question correctly  and  the 
  157.         program  flows  back  to line 9180 to  repeat  the  dialog.   The 
  158.         'LEFT$(A$,Z)'  statement  picks out the first  character  of  the 
  159.         string.  In that way, answers such as 'Y', 'YES'. 'YEP' or  'YUP' 
  160.         will all generate the same correct response to a 'YES' condition, 
  161.         while  'N', 'NO, NOPE' or even 'NO THANKYOU' will all  cause  the 
  162.         'NO'  sequence  to be performed.  This is a  neat  technique  for 
  163.         allowing  the player freedom in replying while at the  same  time 
  164.         minimizing  the amount of program required to detect  and  verify 
  165.         that the reply is valid and desired.
  166.  
  167.              A  length  test must always be performed  before  using  the 
  168.         'LEFT$(A$)',  'RIGHT$(A$)' or MID$(A$,N,L) functions or an  error 
  169.         will  be generated when the function tries to operate on  a  zero 
  170.         length string.  In a zero length string, the first character does 
  171.         not  exist  and  so the computer does not know  what  to  do  and 
  172.         generates  an  "ERROR" message and terminates  the  program.   In 
  173.         dialects  of BASIC that allow error trapping, that error  can  be 
  174.         caught and compensated for.  It is better however to get into the 
  175.         habit  of writing programs that trap potential  erroneous  inputs 
  176.         when  they  are generated, rather than when they  are  processed.  
  177.         You may forget later that an erroneous entry needs to be trapped, 
  178.         not find it in debugging because you didn't test for it, and only 
  179.         later when the program is published do you get many irate letters 
  180.         from readers who used your program, entered lots of data into it, 
  181.         only to lose them all when the program abruptly terminated due to 
  182.         such an error.  Look at articles and listings in magazines.   You 
  183.         will see many that include the sequence
  184.         INPUT "PROMPT OF SOME KIND";A$ : IF LEFT(A$,1)= .  Sloppy!
  185.  
  186.              The  sequence to start a new game begins at line  9210  with 
  187.         the  usual  REMark  statement.  Line 9220 clears  the  screen  by 
  188.         outputting  a  control character in an identical manner  to  that 
  189.         performed  in  line  10.   If you made a change  in  line  10  to 
  190.         implement  the 'clear screen/home cursor' function, make it  here 
  191.  
  192.  
  193.         Copyright (c) Joe Kasser 1989
  194.  
  195.  
  196.  
  197.  
  198.  
  199.         Chapter 7 PAGE 4 STARTREK THE COMPUTER PROGRAM
  200.  
  201.  
  202.         as  well.  As a reminder, the 'PRINT CHR$(26)' does the  job  for 
  203.         the  OSBORNE 1 computer; the TRS-80 wants 'CLS' and the APPLE  II 
  204.         needs 'HOME' to perform the identical operation.
  205.  
  206.              The  cursor  is  then moved down one  line  by  the  'PRINT' 
  207.         statement.  A "WAIT FOR IT" message is then displayed to tell the 
  208.         player that something is going on and the subroutine starting  at 
  209.         line  4660 is called to re-initialize the assorted variables  and 
  210.         flags (including F9).  The program counter is then reset to  line 
  211.         30  to pick up the main game sequence.  It program counter  could 
  212.         not  have  been  reset to lines 10 or 20, because  of  the  'DIM' 
  213.         statement in line 4520, which is part of the subroutine beginning 
  214.         at  line  4500  called  in line 20.  A  'DIM'  statement  on  any 
  215.         particular array can only be carried out once in any one program.  
  216.         Arrays  cannot  be  redimensioned during  the  execution  of  the 
  217.         program which is what the computer would think you were trying to 
  218.         do if the  statement at the end of line 9220 directed the program 
  219.         counter  to 'GOTO' lines 10 or 20.  This is the reason  that  the 
  220.         initialization  procedure  is split into two  parts.   The  first 
  221.         which begins at line 4500 initializes the parameters (such as  Z) 
  222.         and defines all the constants and strings.  The second subroutine 
  223.         starting  at  line 4660 then initializes all  the  variables  and 
  224.         flags.
  225.  
  226.              The  'WAIT  A  MINUTE'  prompt  at  the  start  of  the  re-
  227.         initialization sequence performs an important ergonomic function.  
  228.         Studies  on large time-sharing computer systems have  shown  that 
  229.         people  lose  interest if the response time of  the  computer  is 
  230.         greater  than  two  seconds.   That means if  they  don't  get  a 
  231.         response  from  the  computer  within  two  seconds  of  entering 
  232.         something,  they  tend to lose interest or get annoyed  with  the 
  233.         machine.   It is thus good practice to display a message  telling 
  234.         the  user  that some routine or other is going to take  a  while.  
  235.         That  way, the user will expect the delay and not wonder  if  the 
  236.         computer  has  gone off into some never never land and  left  the 
  237.         user completely alone.
  238.  
  239.              The  game  ends in line 9230 with the 'END'  statement.   In 
  240.         most  dialects of BASIC, the program ends automatically when  the 
  241.         program line after the highest line number is performed.  In this 
  242.         case,  line 9230 is reached by a branch statement in  line  9190.  
  243.         If  line 9230 is the last line of the program, You could  replace 
  244.         it  with  a  program line that displays a  message  thanking  the 
  245.         player  for  playing and indicating the hope that  the  game  was 
  246.         enjoyable.   At  this time however it is not, because  the  10000 
  247.         series of temporary lines are still in it. so the 'END' statement 
  248.         is a requirement.
  249.  
  250.              Carefully copy lines 9000 to 9230 into your program and save 
  251.         them.   Then  'RUN'  the program and debug  these  lines.   Since 
  252.         nothing  has  yet been written that sets F9,  break  the  program 
  253.         using  the ^C character and manually set the contents of F9 to  a 
  254.         value between 1 and 5 inclusive.  You can do that by entering  F9 
  255.         =  1  or some other value.  When you then run  the  program,  you 
  256.         should  see the different endings.  Try all 5  possible  endings, 
  257.  
  258.  
  259.         Copyright (c) Joe Kasser 1989
  260.  
  261.  
  262.  
  263.  
  264.  
  265.         Chapter 7 PAGE 5 STARTREK THE COMPUTER PROGRAM
  266.  
  267.  
  268.         and  answer the question posed by line 9180 in different ways  to 
  269.         test it.  Then when you are satisfied with the performance of the 
  270.         End  of  the game sequence, update line 10 and save  the  program 
  271.         once more.
  272.  
  273.              We are now ready to go on and examine the 'MOV' command.
  274.  
  275.         7.2  The MOVe Command
  276.  
  277.              The Move function is used to navigate the Enterprise  around 
  278.         the galaxy.  The Enterprise is permitted to go outside the galaxy 
  279.         but  in  that event, something will be damaged  as  the  starship 
  280.         crosses  the  Galactic Barrier.   The properties of  faster  than 
  281.         light  travel  are that it will take about one  stardate  to  get 
  282.         anywhere  when traveling at warp speed, but the amount of  energy 
  283.         used is a function of the warp factor.  the faster the ship  goes 
  284.         the more energy is used.  The function is also not linear.   That 
  285.         means that there is no direct correspondence between warp  factor 
  286.         and  energy used.  For example, you can cross the galaxy at  warp 
  287.         factor eight using an enormous amount of energy in one  stardate.  
  288.         You  can also take two days to do it at warp factor four and  use 
  289.         about  a  quarter  of  the energy that  the  warp  eight  journey 
  290.         required.  Travel is thus a trade off between time and energy.
  291.  
  292.            Travel  inside  a quadrant is performed under  Impulse  Power.  
  293.         Using  the impulse engines however is a slow way to  travel.   It 
  294.         takes 0.1 stardates to cross a sector. Thus if you want to travel 
  295.         across seven sectors, you will use up .7 stardates.   The  choice 
  296.         of warp or impulse power is automatic.  If the player specifies a 
  297.         fractional  warp  factor, the impulse engines  are  automatically 
  298.         invoked.   Since this is a static game, the Enterprise is  always 
  299.         brought to rest at its destination.
  300.  
  301.              Several things may happen when traveling as follows.
  302.  
  303.         1    Klingon Space Mines
  304.  
  305.              The  Enterprise  may hit a Klingon Space Mine.  This  is  an 
  306.              energy  weapon  that functions much like a Phaser  hit.   It 
  307.              takes energy out of the shields.  Make sure you travel  with 
  308.              your shields up (with some energy in them).
  309.  
  310.         2    Space Warps
  311.  
  312.              The Enterprise may be caught in a gravitational anomaly  and 
  313.              be physically hurled across the galaxy in zero time.   There 
  314.              is  no way to detect these gravitational anomalies ahead  of 
  315.              time.
  316.  
  317.         3    Ion Storms
  318.  
  319.              Ion  Storms  also  occur  pretty much  at  random.   If  the 
  320.              Enterprise  passes  through such a storm, there  is  a  good 
  321.              probability that the ship will suffer some damage.
  322.  
  323.  
  324.  
  325.         Copyright (c) Joe Kasser 1989
  326.  
  327.  
  328.  
  329.  
  330.  
  331.         Chapter 7 PAGE 6 STARTREK THE COMPUTER PROGRAM
  332.  
  333.  
  334.         4    Mr. Spok At Work
  335.  
  336.              As you already know, Mr. Spok is a marvel.  He is always  at 
  337.              work on the ship.  From time to time, if he has nothing more 
  338.              urgent pending, he may assist the repair section and perform 
  339.              some  special repair action to fix a damaged  sub-system  in 
  340.              ultra fast time.
  341.  
  342.              Now when the starship moves, it can collide with objects  in 
  343.         other sectors.  If you collide with a starbase, you will  receive 
  344.         a  nasty message via sub-space radio.  If you hit a Klingon,  you 
  345.         will  probably damage both vessels, however you cannot destroy  a 
  346.         Klingon by constantly colliding with it.  If you hit a star  then 
  347.         one  of  two things may happen.  You may either go into  a  space 
  348.         warp  condition  due to the gravitational stresses close  to  the 
  349.         sun, or if  the crew can shut down the engines in time, you  will 
  350.         come  to rest in space after an emergency engine shut  down.   It 
  351.         will  then take half a stardate to start the  matter/anti  matter 
  352.         engines again.
  353.  
  354.              Consider  the flow chart for the Move function as  shown  in 
  355.         figure  7.3.  It begins with some dialog to determine  first  the 
  356.         course  and then the warp factor.  If the warp factor entered  is 
  357.         equal to or less than zero, nothing happens.  You could put  some 
  358.         kind  of message here reminding the player that those inputs  are 
  359.         not allowed.  If the desired warp speed is greater than eight,  a 
  360.         message stating that the speed is beyond the capabilities of  the 
  361.         engines.
  362.  
  363.              Assuming an allowable warp factor, the next thing to test is 
  364.         if  that  warp factor was greater than one.   Faster  than  light 
  365.         travel cannot take place if the engines are damaged.  If it  was, 
  366.         a  further  test  is performed to determine if  the  engines  are 
  367.         themselves damaged.  If they are, an "ENGINES DAMAGED" massage is 
  368.         displayed  to  the player. and no further action can  take  place 
  369.         until an allowable warp factor is chosen.
  370.  
  371.              If  the warp factor is greater than one, faster  than  light 
  372.         travel is invoked.   Once the Enterprise begins to move the enemy 
  373.         first get a chance to fire.   A test thus has to be performed  to 
  374.         see if they destroyed the Enterprise during that attack.  If they 
  375.         did,  the rest of the subroutine can be skipped.  The  Enterprise 
  376.         then moves to a new sector. If the sector is occupied a collision 
  377.         occurs.  If the sector is vacant, the Enterprise will either pass 
  378.         through  it or stop in it depending on the warp factor.   If  the 
  379.         Enterprise  moves out of the quadrant, it is then transferred  to 
  380.         the new quadrant.
  381.  
  382.              If  the  time for the random event occurs, it  takes  place.  
  383.         The energy used up in moving is computed and as long as there  is 
  384.         some  energy  left on the ship, the state of repair  of  all  the 
  385.         ship's  on-board  sub-systems is updated, the  condition  of  the 
  386.         Enterprise is then determined, and the subroutine ends.
  387.  
  388.              The   flowchart  of  figure  7.3  described   some   complex 
  389.  
  390.  
  391.         Copyright (c) Joe Kasser 1989
  392.  
  393.  
  394.  
  395.  
  396.  
  397.         Chapter 7 PAGE 7 STARTREK THE COMPUTER PROGRAM
  398.  
  399.  
  400.         operations  in one or two words.  Some of these  operations  must 
  401.         themselves  be described by flowcharts to fully understand  their 
  402.         operations}
  403.  
  404.              The COLLISION is itself a complex event.  It may be expanded 
  405.         into  the flow chart shown in figure 7.4.  The function tests  to 
  406.         see  what  was hit.  If a star was hit there is a  forty  percent 
  407.         probability  that  if there is also no starbase in  the  quadrant 
  408.         that  a  space  warp  will  occur.   Space  warps  occur  due  to 
  409.         gravitational  anomalies, and Starbases are not normally  located 
  410.         near such dangerous phenomena.  If the Enterprise does not  enter 
  411.         a  gravitational  anomaly  the  Engine  Room  will  perform    an 
  412.         emergency engine shut down.  It will then take half a stardate to 
  413.         start up the matter/anti-matter reaction.  If the Enterprise does 
  414.         come to a halt before the star, it has to be backed up one sector 
  415.  
  416.              If  the  Enterprise  has  hit  a  Klingon,  a   message   is 
  417.         displayed,  the  Enterprise is backed up and  one  sub-system  is 
  418.         damaged.  The Klingon does not apparently suffer any damage  that 
  419.         affects its fighting capability due to the collision.
  420.  
  421.              The only other thing that the Enterprise can hit in a sector 
  422.         is a Starbase.  If the Enterprise has hit a Starbase, then it  is 
  423.         first  backed up one sector.  A message is displayed stating  the 
  424.         fact.   The  message  can take one of two forms.   If  there  are 
  425.         Klingons  in  the quadrant, the Enterprise comes to a  halt.   If 
  426.         there  are no Klingons in the quadrant, the starbase sends out  a 
  427.         tractor beam to stop the Enterprise.  The docking procedure  will 
  428.         then  take place in the usual manner.  If there are  Klingons  in 
  429.         the  quadrant,  the Base cannot lower its shields  to  allow  the 
  430.         Enterprise to dock, so the Enterprise comes to a hard stop with a 
  431.         suitable message being displayed.
  432.  
  433.                   The second complex function in the MOVE command is  the 
  434.         MOVE.TO.NEW.QUADRANT function shown in figure 7.5.  It begins  by 
  435.         computing the co-ordinates of the new quadrant the elapsed  time.  
  436.         The new co-ordinates and the old ones are then compared to see if 
  437.         the  Galactic Boundary Barrier has been crossed.  If it has,  one 
  438.         of the on-board sub-systems is damaged.  
  439.  
  440.              The  algorithm to test for crossing the galactic barrier  is 
  441.         as  follows.  The first test is to determine if the new  position 
  442.         of the Enterprise is inside the galaxy,  If it is, we test to see 
  443.         if  the previous position of the Enterprise before it  moved  was 
  444.         also  inside  the galaxy.  If it was, no damage  occurs.   If  it 
  445.         wasn't, the ship crossed the barrier and something gets  damaged.  
  446.         A similar test is performed if the new position of the Enterprise 
  447.         is  outside the galaxy and the old one wasn't.  In that  instance 
  448.         damage also occurs when the barrier is crossed.
  449.  
  450.              The  contents  of  the new sector are then set  up  and  the 
  451.         function ends.
  452.  
  453.              The  remaining  complex  function  is  the  DAMAGE.SOMETHING 
  454.         function shown in figure 7.6.  A subsystem is selected at random.  
  455.  
  456.  
  457.         Copyright (c) Joe Kasser 1989
  458.  
  459.  
  460.  
  461.  
  462.  
  463.         Chapter 7 PAGE 8 STARTREK THE COMPUTER PROGRAM
  464.  
  465.  
  466.         An amount of time is selected  also at random and the  sub-system 
  467.         is damaged (The estimated time to repair (ETR) is updated to that 
  468.         value.   A  message  is then displayed stating  that  damage  has 
  469.         occurred (but not how much) to a particular subsystem.
  470.  
  471.              The BASIC language implementation (excluding the  SHOOT.BACK 
  472.         function) of the MOVE command could take the form shown in figure 
  473.         7.7 which begins in line 1300 with the usual REMark statement.
  474.  
  475.              The  player  dialog setting the direction  of  travel  takes 
  476.         place in line 1310.  The player is asked for and at the same time 
  477.         prompted to give a valid response by the statement
  478.                         INPUT "DIRECTION PLEASE (1-9) ";C 
  479.         The program has told the player what it wants and also the  valid 
  480.         response  limits.   The compass directions used in the  game  are 
  481.         shown  in  figure  7.8.   The input number  is  assigned  to  the 
  482.         variable 'C'.  The second part of the line tests it to see if  it 
  483.         is  valid.  As you can see from the compass, the  direction  must 
  484.         lie  between 1 and 9.  The usual 'IF/THEN' statement is  employed 
  485.         and tests both conditions by including the 'OR' statement in  the 
  486.         test.  If the value of C is less than 1 or is greater than 9,  it 
  487.         is not valid by definition and the program line counter is  reset 
  488.         to  the beginning of the line so the player can respond again  to 
  489.         the question. 
  490.  
  491.              Line 1320 asks the player to input the desired Warp  Factor, 
  492.         which is assigned to the variable 'W'.  The 'INPUT' statement  is 
  493.         again employed for that purpose.  The last part of the line tests 
  494.         the  value of 'W' to ensure that it is a positive value.  If  the 
  495.         player entered a zero or a negative warp factor then the  program 
  496.         counter  is advanced to line 1810 by the 'THEN 1750 part  of  the 
  497.         line, and bypasses the rest of the MOV subroutine.
  498.  
  499.              Line 1330 tests the desired warp factor to see if the wanted 
  500.         speed is faster than the engines can supply.  The enterprise  has 
  501.         a  maximum speed of warp factor 8.  If the player has  entered  a 
  502.         warp factor greater than eight, a message to the effect that  the 
  503.         Enterprise  cannot  go that fast is displayed,  and  the  program 
  504.         counter is then reset to line 1320 to ask the player for a  valid 
  505.         warp  factor.  Notice that the message in line 1330 is  displayed 
  506.         in a scottish accent simulating the voice of Mr. Scott.
  507.  
  508.              Line 1340 tests the state of the engines to see if they  are 
  509.         working.   If  they are, the value in the  damage  control  array 
  510.         'D(I)' is zero and the program counter is advanced to line 1360.
  511.  
  512.              Line  1350 is only reached if the engines are  damaged.   If 
  513.         they  are, the maximum speed is less than warp factor  one.   The 
  514.         line  thus  begins with a test to determine if the  desired  warp 
  515.         factor  is  greater  or equal to one.  If it  is,  a  message  is 
  516.         displayed  stating that the engines are damaged and  the  program 
  517.         counter  is set back to line 1320.  If the test at the  beginning 
  518.         of the line fails, the desired warp factor was less than one, and 
  519.         the  program  counter is advanced to the next  line.   Line  1360 
  520.         contains a 'REM' statement documenting the fact that at this time 
  521.  
  522.  
  523.         Copyright (c) Joe Kasser 1989
  524.  
  525.  
  526.  
  527.  
  528.  
  529.         Chapter 7 PAGE 9 STARTREK THE COMPUTER PROGRAM
  530.  
  531.  
  532.         the  Enterprise begins to move.  It is useful to put comments  in 
  533.         programs  in  the  middle  of subroutines as  well  as  at  their 
  534.         beginnings if the module is complex, and this is one of the  most 
  535.         complicated modules in the whole game.
  536.  
  537.              The  Enterprise  truly  begins to move at  line  1370.   The 
  538.         contents of the sector occupied by the Enterprise is first  reset 
  539.         to  a  blank value.  This is done by the  statement  'S(S1,S2)=Z' 
  540.         which assigns the value one (represented by the parameter 'Z') to 
  541.         the  contents  of the sector defined by the co-ordinates  of  the 
  542.         Enterprise.   Remember, the S(I,J) array stores the  contents  of 
  543.         the sectors, and, the variables S1 and S2 contain the sector  co-
  544.         ordinates of the Enterprise.  The time remaining before the  move 
  545.         takes place is saved in the temporary time variable (T1) by using 
  546.         the implied 'LET' statement
  547.                                       T1=T.  
  548.         If  the  warp  factor  is  greater than  or  equal  to  one,  the 
  549.         Enterprise  is  by definition, about to leave the  quadrant.   In 
  550.         that  case,  if there are any Klingons in the quadrant  they  are 
  551.         given a chance to fire at the Enterprise by the statement
  552.                         IF K>0 AND W>=Z THEN GOSUB 600.  
  553.         If  the enemy have had a chance to shoot at the  Enterprise,  the 
  554.         possibility exists, that they have been able to destroy the ship.  
  555.         The  last part of the line tests the value of the game over  flag 
  556.         (F9).  If it is greater than zero, something has happened to  the 
  557.         Enterprise,  so  the  program counter is advanced  to  line  1750 
  558.         bypassing the remainder of the routine.
  559.  
  560.              Line  1370 contains two 'IF' statements in series.   It  may 
  561.         make it clearer if the statements were written as
  562.  
  563.         IF   (1)  K>0 AND W>=Z 
  564.         THEN (1)  GOSUB 600
  565.                   IF   (2)  F9>0 
  566.                   THEN (2)  1750
  567.                   ELSE (2)
  568.         ELSE (1).
  569.  
  570.              If  the test (1) fails, namely either there are no  Klingons 
  571.         in the quadrant, or the warp factor is less than one, the program 
  572.         counter picks up after the 'ELSE (1)' statement.  If the test  is 
  573.         true,  the  subroutine starting at line 600 is  invoked  and  the 
  574.         second    test   performed.    The   correlation   between    the 
  575.         'IF/THEN/ELSE' statement and the 'YES/NO/THEN' of the flow  chart 
  576.         is
  577.  
  578.         LOGIC POINT         FLOWCHART      BASIC
  579.         ----------------------------------------
  580.         TEST STATEMENT      =?             IF
  581.         RESULT IS TRUE      YES            THEN
  582.         RESULT IS FALSE     NO             ELSE
  583.         PICK UP POINT       THEN           following line.
  584.  
  585.         In BASIC there is then no clear point where the two logical flows 
  586.         merge again, unlike the flow chart.  That is probably the  reason 
  587.  
  588.  
  589.         Copyright (c) Joe Kasser 1989
  590.  
  591.  
  592.  
  593.  
  594.  
  595.         Chapter 7 PAGE 10 STARTREK THE COMPUTER PROGRAM
  596.  
  597.  
  598.         why  various  dialects  of BASIC treat  the  'IF/THEN'  statement 
  599.         differently, and cause major problems in converting programs that 
  600.         run  on one machine to run on an other even though they both  use 
  601.         "BASIC".
  602.  
  603.              Line  1380  loads the move variables.   The  move  operation 
  604.         inside the quadrant is performed half a sector at a time  because 
  605.         later  on, we will be dealing with integer sector values.  Y1  is 
  606.         set  to the S1 co-ordinate (plus half a sector), X1 is  similarly 
  607.         set  to the S2 co-ordinate.  Y is set to an angle in  radians  by 
  608.         using a conversion constant.  If you are mathematically inclined, 
  609.         remember  that  the game uses directions  as  compass  positions.  
  610.         They  have  to be converted to an angle in order to  compute  the 
  611.         movement  of  the ship.  BASIC contains  built  in  trigonometric 
  612.         functions  that operate on angles represented in radians  not  in 
  613.         degrees.   Conversion  factors  exist.  X and Y are  set  to  the 
  614.         vector  of  the  desired direction expressed along  the  row  and 
  615.         column  directions.   If  you understand  trigonometry  you  will 
  616.         follow what is happening here.  if not, don't worry about it.
  617.  
  618.              The  loop that actually moves the Enterprise begins in  line 
  619.         1390.  It is expressed on the form of a 'FOR/NEXT' loop from zero 
  620.         to the integer of the warp factor multiplied by eight (number  of 
  621.         sectors  horizontally  or vertically in a quadrant).   This  loop 
  622.         thus  moves the Enterprise up to the edge of the quadrant if  the 
  623.         warp  factor was greater than one.  If it was less than one,  the 
  624.         ship will move the correct number of sectors within the quadrant.  
  625.         It  may  also go over the edge. For each  sector,  the  temporary 
  626.         position  co-ordinates are then (Y1 and X1) updated.   These  co-
  627.         ordinates  are then converted to integers as two  more  temporary 
  628.         variables  (Y2  and  X2) so that they can be  used  to  test  the 
  629.         contents of the Sector array S(X,Y).
  630.  
  631.              Line 1400 first tests to see if the Enterprise has moved out 
  632.         of  the quadrant.  Remember that the Enterprise will  be  outside 
  633.         the  quadrant if either Y2 or X2 are less than 0 or greater  than 
  634.         7.   If any of them are, the program flow is skipped  forward  to 
  635.         line 1490.
  636.  
  637.              Line  1410 uses the 'ON' statement to test the state of  the 
  638.         sector that the Enterprise has been moved to.  The correspondence 
  639.         between the contents of the sector and the 'GOTO' is as follows
  640.  
  641.         SECTOR         GOTO LINE
  642.         1              1480
  643.         2              1420
  644.         3              1480
  645.         4              1440
  646.         5              1450.
  647.  
  648.         If we remember the convention used to set up the contents of  the 
  649.         sector,  and the letters used to represent them we  can  generate 
  650.         the following 
  651.  
  652.  
  653.  
  654.  
  655.         Copyright (c) Joe Kasser 1989
  656.  
  657.  
  658.  
  659.  
  660.  
  661.         Chapter 7 PAGE 11 STARTREK THE COMPUTER PROGRAM
  662.  
  663.  
  664.         SECTOR         CONTENTS       LETTER    GOTO LINE
  665.         1              BLANK          .         1480
  666.         2              STAR           *         1420
  667.         3              ENTERPRISE     E       1480      
  668.         4              KLINGON        K         1440
  669.         5              STARBASE       B         1450.
  670.  
  671.         Thus  the 'ON' statement directs the program to process the  move 
  672.         as a function of what is in the sector.
  673.  
  674.              If there is a star in the sector, the value of S(X2,Y2) will 
  675.         be 2 and the program picks up at line 1420 which first displays a 
  676.         warning message "STAR DEAD AHEAD".  If there are no starbases  in 
  677.         the  quadrant, there is then a random probability of 40%  that  a 
  678.         gravitational  anomaly has been intercepted as the ship  came  to 
  679.         close to the star, and a space warp is entered.  This is achieved 
  680.         in BASIC by the statement
  681.                         'IF RND(Z)>.6 AND B=0 THEN 1640' 
  682.         which  directs  the program to branch forward to line 1640  if  a 
  683.         random number is greater than 0.6 and the value of B (the  number 
  684.         of starbases in the quadrant) is zero.
  685.  
  686.              If the Enterprise does not go into a Space Warp, the program 
  687.         continues  at  line  1430 (the next line number  in  sequence  by 
  688.         default).  An "EMERGENCY ENGINE SHUT DOWN" message is  displayed,   
  689.         The  engines  are  then damaged by adding 0.5  stardates  to  the 
  690.         estimated  repair  time.   This is  done  by  the  'D(0)=D(0)+.5' 
  691.         statement  which  adds  0.5 to whatever value is  stored  in  the 
  692.         element  of the damage control array associated with the  engines 
  693.         (ie.  D(0)  ).   The subroutine beginning at line  1780  is  then 
  694.         invoked  to  back  the  Enterprise up  one  sector  to  the  last 
  695.         unoccupied  sector  and lastly, the program is advanced  to  line 
  696.         1720.
  697.  
  698.              The collision with the Klingon is catered for in line  1440.  
  699.         The  cursor  is  advanced one line by the  'PRINT'  statement.  A 
  700.         warning  message  is then displayed by the 'PRINT "STAND  BY  FOR 
  701.         COLLISION WITH KLINGON" 'statement. The backing up subroutine  of 
  702.         line 1780 is then invoked. The subroutine starting at line 110 is 
  703.         called.   Remember  that  when the  Enterprise  collides  with  a 
  704.         Klingon, it suffers damage to the on board sub-system closest  to 
  705.         the point of collision.  Since there is no way to establish which 
  706.         way the Enterprise is facing, the random damage function is  used 
  707.         to  simulate  the  event.  When all this  is  done,  the  program 
  708.         counter is advanced to line 1720.
  709.  
  710.              Line  1450  takes care of the situation wherein there  is  a 
  711.         collision with a Starbase.  For the sake of variety the order  of 
  712.         the  events is changed.  Thus the backing up subroutine  of  line 
  713.         1780  is  invoked first.  The message is  displayed  second,  and 
  714.         lastly if there are Klingons in the quadrant, a sarcastic message 
  715.         is displayed and the program counter is advanced to line 1720  as 
  716.         usual.   Thus  if  there  are  Klingons  in  the  quadrant,   the 
  717.         Enterprise  cannot dock at a Starbase by colliding with  it.   If 
  718.         there  are no Klingons in the quadrant, the program picks  up  at 
  719.  
  720.  
  721.         Copyright (c) Joe Kasser 1989
  722.  
  723.  
  724.  
  725.  
  726.  
  727.         Chapter 7 PAGE 12 STARTREK THE COMPUTER PROGRAM
  728.  
  729.  
  730.         line 1460, which displays a warning message.  Line 1470 then uses 
  731.         a  'GOTO' statement to advance the program counter to line  1720.  
  732.         There is real no reason why line 1460 could not have read
  733.  
  734.         1460 PRINT "ENTERPRISE CAUGHT IN TRACTOR BEAM BEFORE COLLISION" : GOTO 1720
  735.  
  736.              The  in-sector  move loop terminates at line 1480.   If  the 
  737.         loop is still in process when the loop times out, the  Enterprise 
  738.         is still inside the quadrant and must be conditioned accordingly.
  739.  
  740.              Look  back  to  line 1410 at this  time  and  consider  what 
  741.         happened  on the various values of S(I,J) or the contents of  the 
  742.         quadrants that the Enterprise passes through as it travels across 
  743.         the  quadrant.   We stated before that line 1410  uses  the  'ON' 
  744.         statement to test the state of the sector that the Enterprise has 
  745.         been moved to.  If we remember the convention used to set up  the 
  746.         contents of the sector, and the letters used to represent them we 
  747.         can generate the following 
  748.  
  749.         SECTOR         CONTENTS       LETTER    GOTO LINE
  750.         1              BLANK          .         1480
  751.         2              STAR           *         1420
  752.         3              ENTERPRISE     E         1480      
  753.         4              KLINGON        K         1440
  754.         5              STARBASE       B         1450.
  755.  
  756.         Thus  line  1480  is always invoked when  the  Enterprise  passes 
  757.         through  a  blank or empty quadrant.  The condition  S(I,J)  =  3 
  758.         should  not  occur, because if it does, the  Enterprise  will  be 
  759.         passing  through  a  sector that  contains  itself.   There  does 
  760.         however have to be an entry in the implied GOTO list of the  'ON' 
  761.         states  corresponding  to the S(I,J) = 3  condition.   The  entry 
  762.         chosen here is to advance the program counter to line 1480 as  if 
  763.         the  Sector was vacant.  You could put an error trapping  message 
  764.         display  here, but that would confuse the player.  This way,  the 
  765.         program ignores hopefully the condition and passes on to the next 
  766.         sector.
  767.  
  768.              The  first item in line 1480 is the 'NEXT'  statement  which 
  769.         increments the loop counter and sets up another iteration of  the 
  770.         loop  if the loop counter does not time out. If the loop  counter 
  771.         does time out, the Enterprise is still inside the same  quadrant.  
  772.         The  internal co-ordinates (S1 and S2) are then set up,  and  the 
  773.         value of the sector occupied by the Enterprise is set to 3 by the 
  774.         'S(Y2,X2)=3'  statement.  This sets the value of the  element  in 
  775.         the S(I,J) array to 3 where I = Y2 and J = X2.  The last  element 
  776.         on the line points the program counter to line 1580 bypassing the 
  777.         section of code which deals with the out-of-sector condition.
  778.  
  779.              The  out of sector section of the subroutine begins at  line 
  780.         1490 with a REM statement.  There is no reason why REM statements 
  781.         cannot be used inside a subroutine as well as at the beginning of 
  782.         one.   Use them anytime you wish to remember which line  of  code 
  783.         does what.
  784.  
  785.  
  786.  
  787.         Copyright (c) Joe Kasser 1989
  788.  
  789.  
  790.  
  791.  
  792.  
  793.         Chapter 7 PAGE 13 STARTREK THE COMPUTER PROGRAM
  794.  
  795.  
  796.              Line 1510 tests the new co-ordinates of the starship to  see 
  797.         if it inside the Galaxy.  Remember that for the Enterprise to  be 
  798.         inside the galaxy, the row and column quadrant co-ordinates  must 
  799.         lie between 0 and 7.  The new values of Q1 and Q2 are thus tested 
  800.         by  the  now  familiar ' IF Q1<0 OR Q1>7 OR Q2<0  OR  Q2>7  THEN' 
  801.         statement.   If the test is true, namely one or more of  the  co-
  802.         ordinates  show that the Enterprise is outside the  galaxy,  then 
  803.         the program counter is advanced to line 1550.
  804.  
  805.              Line 1520 contains a REMark to the effect, that the  section 
  806.         of  the  program  dealing with the Enterprise  taking  up  a  new 
  807.         position inside the Galaxy.  The first thing line 1530 does is to 
  808.         test  the value of the variable G9 used as a flag to indicate  if 
  809.         the previous position of the Enterprise was inside or outside the 
  810.         Galaxy.  If the value of G9 was one (Z) then the  Enterprise  was 
  811.         outside the galaxy and is now inside it.  The subroutine starting 
  812.         at line 1760 is invoked which takes care of the events that occur 
  813.         when  the Enterprise crosses the Galactic boundary barrier.   The 
  814.         value  of G9 is then set to zero.  Line 1540 then  positions  the 
  815.         program counter to line 1570.
  816.  
  817.              Line  1550  is  invoked if the  Enterprise  is  outside  the 
  818.         Galaxy. Now, if the Enterprise was previously inside the  galaxy, 
  819.         ie the value of G9 is 0, then the boundary crossing subroutine of 
  820.         line  1760 is invoked before setting the value of G9 to one  (Z).  
  821.         Note  that the value of G9 is only adjusted if it changes.   Thus 
  822.         in  lines 1530 and 1550, the value of G9 is only changed  if  the 
  823.         tests pass.
  824.  
  825.                   The  section  of the program that introduces  a  random 
  826.         probability of something happening during the move begins at line 
  827.         1580.    A   random  integer  number  is  generated  by   the   ' 
  828.         I=INT(RND(Z)*100) ' statement.  This is a complex statement  made 
  829.         up  of  the following statements.  I = RND(Z) : I = I*100 :  I  = 
  830.         INT(I).   The  resultant value of I is then tested to see  if  it 
  831.         zero  or  greater  than  4.  If it is,  the  program  counter  is 
  832.         advanced  to  line  1720, bypassing the  random  event  routines.  
  833.         Note,  thus the very low probability of a random  event,  because 
  834.         given a random value between 0 and 99, a random event only occurs 
  835.         if the value of I (the random number) is either 1 or 2 or 3 or 4.
  836.  
  837.              The  statements  on the line could alternatively  have  been 
  838.         written as 
  839.                     I=INT(RND(Z)*100)+Z : IF I>4 THEN 1720.  
  840.         Here  the I=0 condition would never arise because the value of  I 
  841.         is  always  set to one by the '+Z' part of the  statement.   Thus 
  842.         there  is  no need to test for the I=0 condition  in  the  second 
  843.         statement.  Both versions of the line are correct and work.  Each 
  844.         one  however will have a different execution speed.  In  practice 
  845.         the actual difference is so small that it can be ignored.
  846.  
  847.              Line 1590 tests the value of the G9 flag.  If it is set  (ie 
  848.         G9  = 1), then the program counter is advanced to line 1680.   Of 
  849.         the  four random events that occur during a move operation,  only 
  850.         one  is  beneficial to the player.  The sections of  the  program 
  851.  
  852.  
  853.         Copyright (c) Joe Kasser 1989
  854.  
  855.  
  856.  
  857.  
  858.  
  859.         Chapter 7 PAGE 14 STARTREK THE COMPUTER PROGRAM
  860.  
  861.  
  862.         serving  that one, begin at line 1680.  LIne 1590  thus  inhibits 
  863.         the harmful random events from occurring while the Enterprise  is 
  864.         outside the galaxy.
  865.  
  866.              From  line 1600 on, the Enterprise is inside the Galaxy.   A 
  867.         'PRINT' statement is invoked to move the display cursor down  one 
  868.         line.  Then a statement tests the quadrant to see if it  contains 
  869.         a  starbase.   If it does, the random events are  once  more  by-
  870.         passed  by the statement 'IF B>0 THEN 1720'.  Allowing a  harmful 
  871.         event  to  occur when the player is crawling back to  a  starbase 
  872.         with  a  badly  damaged  ship,  constitutes  cruel  and   unusual 
  873.         punishment.   Allowing  Mr.  Spok to effect  a  repair  when  the 
  874.         starbase  can  do it just as well or even better also  serves  no 
  875.         purpose.   For  these reasons the random events are  bypasses  in 
  876.         this situation.  You could argue that if the engines are damaged, 
  877.         Mr.  Spok could be allowed to repair them so the ship can get  to 
  878.         the base quicker, or if the Short Range Sensors are out, he could 
  879.         be allowed to fix them since the range of the Visual sensors  are 
  880.         limited.   You  may  be right, and  can  readily  implement  that 
  881.         function  by changing the line number following the  'GOTO'  from 
  882.         1720  to 1680.  I have taken the stand that if the bad thins  are 
  883.         inhibited, the good ones will be as well.
  884.                   The   four  random  events  are  associated  with   the 
  885.         following line numbers.
  886.  
  887.         1620      KLINGON SPACE MINE 
  888.         1640      SPACE WARP   
  889.         1670      ION STORM 
  890.         1680      Mr. Spok at work.
  891.  
  892.              The choice of which event occurs is made on line 1610 by the 
  893.         statement
  894.                         'ON I GOTO 1620,1640,1670,1680' 
  895.         which sets the program counter depending on the value of I.   Let 
  896.         us now consider the programs associated with each event.
  897.  
  898.              Line 1620 kicks off with the first event, namely the Klingon 
  899.         Space Mine.  A visual and audible warning message is generated by 
  900.         the statement 
  901.                       PRINT CHR$(7);"KLINGON SPACE MINE ".
  902.         CHR$(7)  is  the ASCII character used by a standard  terminal  to 
  903.         sound  the bell tone. Try typing PRINT CHR$(7) when in the  BASIC 
  904.         command  mode to illustrate this fact to yourself.  BASIC  is  in 
  905.         the command mode when you are typing in programs  or have  broken 
  906.         the  execution of a program with a ^C character and are  entering 
  907.         values directly to memory.
  908.  
  909.              A random value between 0 and 399 for the energy contained in 
  910.         the  hit (H) is generated by the 'H=RND(Z)*400'  statement.   The 
  911.         subroutine  starting  at line 130 is then invoked to  cause  some 
  912.         damage to the Enterprise and the last statement on the line tests 
  913.         the  state  of the End of the Game Flag (F9).  If it  is  greater 
  914.         than  zero,  the  Enterprise  was  destroyed  in  the  subroutine 
  915.         beginning at line 130.  The most likely cause was that the amount 
  916.         of  energy in the Space MIne hit was greater than the  amount  of 
  917.  
  918.  
  919.         Copyright (c) Joe Kasser 1989
  920.  
  921.  
  922.  
  923.  
  924.  
  925.         Chapter 7 PAGE 15 STARTREK THE COMPUTER PROGRAM
  926.  
  927.  
  928.         energy in the shields.  That will however be discussed below.  If 
  929.         the  ship has been destroyed, the program counter is advanced  to 
  930.         line  1750  which  contains the  statement  that  terminates  the 
  931.         subroutine.   If the Enterprise is still operational,  line  1630 
  932.         displays a message telling the player how much energy is left  in 
  933.         the  shields, and then skips the remaining random events part  of 
  934.         the  sub-routine  by advancing the program line counter  to  line 
  935.         1720.   The  'PRINT'  statement here mixes  ASCII  text  and  the 
  936.         contents of the variable E1 and uses the semi-colon to format the 
  937.         display.
  938.  
  939.              The lines of code implementing the Space Warp function begin 
  940.         at  line 1640 by displaying a message telling the player  that  a 
  941.         space warp has been encountered.
  942.  
  943.             The Ion Storm function is contained on line 1670.  An audible 
  944.         and visual warning message is generated by the first statement in 
  945.         the  line.  The nested subroutine at line 110 is then invoked  to 
  946.         damage  one  of the on-board subsystems, and lastly  the  program 
  947.         counter  is advanced to line 1720 bypassing the remainder of  the 
  948.         random events.
  949.  
  950.              The  subroutines associated with the move function begin  at 
  951.         line 1760.  The first one is a one line subroutine that  performs 
  952.         the  galactic  boundary  crossing.  The first part  of  the  line 
  953.         displays  a  message telling the player that  the  Enterprise  is 
  954.         crossing galactic boundary barrier.  A nested subroutine starting 
  955.         at  line  110  is then invoked and the  line  terminates  with  a 
  956.         'RETURN' statement closing the subroutine.   Crossing the barrier 
  957.         at  the edge of the galaxy is a traumatic event.  The  subroutine 
  958.         starting  at line 110 will cause one of the on-board  sub-systems 
  959.         to  be damaged.  This is in line with the model of the galaxy  as 
  960.         described by the TV. series.  Note that line 1760 could also have 
  961.         been written as
  962.           1760 PRINT "CROSSING BARRIER at GALACTIC BOUNDARY" : GOTO 110 
  963.         which does the same job, because the 'RETURN' from the subroutine 
  964.         starting at line 110 would take the program counter back directly 
  965.         to  the  statement  following the one that  called  the  galactic 
  966.         barrier crossing routine.
  967.  
  968.              The two options can be demonstrated as follows.  The  method 
  969.         used in the listing requires two 'RETURN' statements because  the 
  970.         subroutines are nested, namely
  971.  
  972.         CALLING LINE
  973.         GOSUB 1760 
  974.              GOSUB 110  
  975.              RETURN
  976.         RETURN
  977.  
  978.         the  alternative method only uses one 'RETURN' statement  because 
  979.         the  subroutines  are not actually nested, the  'GOTO'  statement 
  980.         joins them together as one, as follows.
  981.  
  982.  
  983.  
  984.  
  985.         Copyright (c) Joe Kasser 1989
  986.  
  987.  
  988.  
  989.  
  990.  
  991.         Chapter 7 PAGE 16 STARTREK THE COMPUTER PROGRAM
  992.  
  993.  
  994.         CALLING LINE
  995.         GOSUB 1760 
  996.         GOTO 110
  997.         RETURN
  998.  
  999.              The  method  used  in the program  is  the  more  structured 
  1000.         version,  because  it is easy to follow what is  happening.   The 
  1001.         second   or  alternative  technique  uses  less  memory  and   is 
  1002.         marginally  faster  in execution (fewer  instructions  are  being 
  1003.         performed)  but  is more difficult to follow when  searching  the 
  1004.         listing  to figure out what is happening.  Both  methods  however 
  1005.         work as well as each other.
  1006.  
  1007.              Line 1780 contains the REMark statement for the single  line 
  1008.         subroutine of line 1790 which backs the Enterprise up one  sector 
  1009.         after  a collision.  The values of S1 and S2 (the  in-sector  co-
  1010.         ordinates of the starship are reset back to their previous values 
  1011.         by subtracting the last increment (Y or X) from the current value 
  1012.         at the sector of collision (Y1 or X1) using the statements
  1013.                          'S1=INT(Y1-Y) : S2=INT(X1-X)'.
  1014.         The  value  of  the sector that the Enterprise  has  backed  into 
  1015.         represented in the sector array (S(I,J)) by S(S1,S2) is then  set 
  1016.         to  3,  ie. the value that shows that the Enterprise  is  in  the 
  1017.         sector, and the 'RETURN' statement at the end of the line  closes 
  1018.         out the subroutine.
  1019.  
  1020.                 The  subroutine  that performs on board  repairs  to  the 
  1021.         starship  as  time passes begins at line 1800.  It  can  be  best 
  1022.         described with reference to the flow chart of figure 7.9
  1023.  
  1024.                 The  Damage  Something flowchart of figure  7.10  can  be 
  1025.         implemented in BASIC in a number of ways.  The method chosen here 
  1026.         was  listed in figure 7.11.     The damage something  subroutine 
  1027.         begins at line 110 with the usual REMark.
  1028.  
  1029.         Line 120 performs the action.  The variable Y is set to a  random 
  1030.         value   between  1  and  whatever  warp  factor  was  last   used 
  1031.         (represented by the variable 'W').  The variable X is then set to 
  1032.         an  integer  value equal to one of the damageable  on-board  sub-
  1033.         system.  They are defined as C1-C2, where C1 is the total  number 
  1034.         of  Commands or sub-systems in the game, and C2, the number  that 
  1035.         cannot  be  damaged.  For example, the VISual  sensor  cannot  be 
  1036.         damaged by definition.  These two variables are dummy values used 
  1037.         to  pass  the random numbers to the  next  statement  D(Y)=X+D(Y)  
  1038.         which  adds the time represented by the random number 'Y' to  the 
  1039.         state  of  repair  of the subsystem  represented  in  the  damage 
  1040.         control  array by the value in the 'Y' th element or  d(Y).   The 
  1041.         damage  done message is then displayed by the 'PRINT'  statement, 
  1042.         and  the  'RETURN' instruction terminates both the line  and  the 
  1043.         subroutine.
  1044.  
  1045.              The  ENERGYHIT routine can be written in basic as  shown  in 
  1046.         figure 7.12.
  1047.  
  1048.              Delete lines the temporary Move function lines 1605 to  1625 
  1049.  
  1050.  
  1051.         Copyright (c) Joe Kasser 1989
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.         Chapter 7 PAGE 17 STARTREK THE COMPUTER PROGRAM
  1058.  
  1059.  
  1060.         and carefully enter lines 1600 to 2170 and lines 120 to 180.  For 
  1061.         debug purposes change line 1870 from 
  1062.         1870 I = INT(RND(Z)*100) : IF I = 0 OR I>4 THEN 2020
  1063.         to
  1064.         1870 I = INT(RND(Z)*5) : IF I = 0 OR I>4 THEN 2020
  1065.         changing  the  100 to 5 will vastly speed up the  occurrences  of 
  1066.         random events allowing you to test all the functions.  Then  when 
  1067.         you  are  satisfied  with  the  operation  of  the  random  event 
  1068.         generator change the line back.
  1069.  
  1070.              Debug  the code by executing all possible  conditions.   See 
  1071.         what happens if you try to move at warp 10, or warp 0 as well  as 
  1072.         legal warp speeds.  Try traveling at less than warp one.  Do  you 
  1073.         end  up in the right place.  Are messages printed out  when  they 
  1074.         should  be.   What happens when you cross the  galactic  boundary 
  1075.         barrier?    Something  should  get  damaged.   Does  the   repair 
  1076.         subroutine  work  correctly?   What happens when  the  Enterprise 
  1077.         runs out of Energy or the shields are beaten down to below  zero.  
  1078.         If  you  get fed up running out of energy during  this  debugging 
  1079.         phase,  stop the program (Control - C) and enter E = 99999999  or 
  1080.         E1  = 99999, then continue.   Follow the listing and  test  every 
  1081.         branch  condition both ways.  Make sure that every piece of  code 
  1082.         on every line is exercised at least once.
  1083.  
  1084.              If you don't have the patience to move around a lot you  can 
  1085.         cheat and dummy up a quadrant.  If for example,you are  currently 
  1086.         residing  at quadrant 3,1, break the program and enter  Q(3,1)  = 
  1087.         717.   This  will  set up Quadrant 3,1  to  seven  Klingons,  one 
  1088.         Starbase and seven stars.  Then continue the program and move  at 
  1089.         warp 1.4 in direction 8, which will move you into the dummied  up 
  1090.         quadrant.  Now move around inside it.  Collide with what you like 
  1091.         and test what happens when a collision occurs.  Debug the routine 
  1092.         and then save the program.
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.         Copyright (c) Joe Kasser 1989
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.